package com.fsh.anime.controller;

import com.fsh.anime.model.dtos.BuyTicketsDto;
import com.fsh.anime.model.dtos.PartyAllDto;
import com.fsh.anime.model.dtos.PartyQueryDto;
import com.fsh.anime.model.vos.Result;
import com.fsh.anime.service.PartyService;
import com.fsh.anime.service.TicketService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/api/party")
@Slf4j
public class PartyController {
    @Autowired
    private PartyService partyService;
    @Autowired
    private TicketService ticketService;

    //----------后台------------

    /**
     * 获取漫展列表 （前台后台通用）
     */
    @PostMapping("/getPartiesForBack")
    public Result getPartiesForBack(@RequestBody PartyQueryDto dto){
        return partyService.getPartiesForBack(dto);
    }


    /**
     * 添加漫展
     */
    @PostMapping("/addPartyShow")
    public Result addPartyShow(@Validated @RequestBody PartyAllDto partyAllDto, BindingResult results){
        if (results.hasErrors()){
            return Result.success(results.getFieldError().getDefaultMessage());
        }

        log.info("PartyController.addPartyShow.partyAllDto={},{}",partyAllDto.getId(),partyAllDto.getTitle());
        return partyService.addPartyShow(partyAllDto);
//        return null;
    }


    /**
     * 查询漫展活动
     */
    @PostMapping("/queryByStateAndTitle")
    public Result queryByStateAndTitle(@RequestBody PartyQueryDto dto){
        log.info("PartyController.queryByStateAndTitle.dto={}",dto);
        return partyService.queryBystateAndTitle(dto);
    }

    /**
     * @param file
     * @return {@link String}
     * 上传漫展 封面 的图片
     */
    @PostMapping("/uploadImg")
    public String uploadImg(MultipartFile file){
        return partyService.uploadImg(file);
    }

    // -----------------前台-------------------

    /**
     * 获取漫展列表 （前台后台通用）
     */
    @PostMapping("/getParties")
    public Result getParties(@RequestBody PartyQueryDto dto){
        return partyService.getParties(dto);
    }

    /**
     * 获取某个漫展内容详情
     */
    @GetMapping("/getPartyContent")
    public Result getPartyContent(String id){
        return partyService.getPartyContent(id);
    }

    /**
     * 获取某个漫展内容详情
     */
    @GetMapping("/getPartyInfo")
    public Result getPartyInfo(String id){
        return partyService.getPartyInfo(id);
    }

    /**
     * 购买门票
     */
    @PostMapping("/buyTicket")
    public Result buyTicket(@RequestBody BuyTicketsDto dto){
        return ticketService.buyTicket(dto);
    }

    /**
     * 获取当期用户购买的所有门票
     */
    @GetMapping("/getTickets")
    public Result getTickets(){
        return ticketService.getTickets();
    }

}
